{% extends "base.html" %}

{% block content %}
<div class="row">
    <div class="col-md-12 mb-4">
        <div class="d-flex justify-content-between align-items-center">
            <h2>用户管理</h2>
            <a href="{{ url_for('admin.index') }}" class="btn btn-outline-primary">返回管理面板</a>
        </div>
    </div>
</div>

<div class="row">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header bg-primary text-white">
                <h5 class="mb-0">所有用户</h5>
            </div>
            <div class="card-body">
                <div class="table-responsive">
                    <table class="table table-hover">
                        <thead>
                            <tr>
                                <th>ID</th>
                                <th>用户名</th>
                                <th>姓名</th>
                                <th>角色</th>
                                <th>注册时间</th>
                                <th>文章数</th>
                                <th>技能数</th>
                                <th>操作</th>
                            </tr>
                        </thead>
                        <tbody>
                            {% for user in users %}
                            <tr>
                                <td>{{ user.id }}</td>
                                <td>{{ user.username }}</td>
                                <td>{{ user.name }}</td>
                                <td>
                                    <span class="badge {% if user.role == 'admin' %}bg-danger{% else %}bg-secondary{% endif %}">
                                        {{ '管理员' if user.role == 'admin' else '成员' }}
                                    </span>
                                </td>
                                <td>{{ user.created_at.strftime('%Y-%m-%d') }}</td>
                                <td>{{ user.articles.count() }}</td>
                                <td>{{ user.skills|length }}</td>
                                <td>
                                    <div class="btn-group" role="group">
                                        <a href="{{ url_for('users.profile', id=user.id) }}" class="btn btn-sm btn-outline-primary">查看</a>
                                        <a href="{{ url_for('admin.edit_user', id=user.id) }}" class="btn btn-sm btn-outline-warning">编辑</a>
                                        {% if user.id != current_user.id %}
                                        <a href="{{ url_for('admin.delete_user', id=user.id) }}" class="btn btn-sm btn-outline-danger" onclick="return confirm('确定要删除此用户吗？此操作不可撤销，用户的所有文章也将被删除。');">删除</a>
                                        {% endif %}
                                    </div>
                                </td>
                            </tr>
                            {% endfor %}
                        </tbody>
                    </table>
                </div>
                
                {% if not users %}
                <div class="alert alert-info">暂无用户</div>
                {% endif %}
            </div>
        </div>
    </div>
</div>

<div class="row mt-4">
    <div class="col-md-12">
        <div class="card">
            <div class="card-header bg-success text-white">
                <h5 class="mb-0">创建新用户</h5>
            </div>
            <div class="card-body">
                <p>作为管理员，您可以创建新用户账号。</p>
                <a href="{{ url_for('auth.register') }}" class="btn btn-success">注册新用户</a>
            </div>
        </div>
    </div>
</div>
{% endblock %}